package control;

import model.object.ObjectUser;
import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.talknow.R;
import common.Const;

public class Screen6Activity extends Activity implements OnClickListener {

	ObjectUser objUser;
	Button button1, button2, button3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_screen_6);
		try {
			objUser = (ObjectUser) getIntent().getExtras().getSerializable(
					Const.KEY_OBJECT);
			((TextView) findViewById(R.id.screen_6_text_id)).setText(objUser
					.getUserid());
		} catch (Exception e) {
			// TODO: handle exception
		}

		((Button) findViewById(R.id.screen_6_button_nho))
				.setOnClickListener(this);
		((Button) findViewById(R.id.screen_6_button_copy_id))
				.setOnClickListener(this);

		button1 = (Button) findViewById(R.id.screen_6_button_facebook);
		button2 = (Button) findViewById(R.id.screen_6_button_line);
		button3 = (Button) findViewById(R.id.screen_6_button_skype);

		button1.setOnClickListener(this);
		button2.setOnClickListener(this);
		button3.setOnClickListener(this);

		AdView adView = (AdView) this.findViewById(R.id.app_admob);
		AdRequest request = new AdRequest.Builder()
				.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
				.addTestDevice("9234EBAE83E894E6271DEBE7B380782E").build();
		adView.loadAd(request);
	}

	@SuppressWarnings("deprecation")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent;
		Toast toat;
		switch (v.getId()) {
		case R.id.screen_6_button_nho:
			finish();
			break;
		case R.id.screen_6_button_copy_id:
			ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
			clipboard.setText(objUser.getUserid());
			toat = Toast.makeText(getBaseContext(), "Copied",
					Toast.LENGTH_SHORT);
			toat.setGravity(Gravity.CENTER, 0, 0);
			toat.show();
			break;
		case R.id.screen_6_button_facebook:
			try {
				intent = new Intent("android.intent.category.LAUNCHER");
				intent.setClassName("com.facebook.katana",
						"com.facebook.katana.LoginActivity");
				startActivity(intent);
			} catch (Exception e) {
				// TODO: handle exception
				Intent browserIntent = new Intent(
						Intent.ACTION_VIEW,
						Uri.parse("https://play.google.com/store/apps/details?id=com.facebook.katana"));
				startActivity(browserIntent);
			}
			break;
		case R.id.screen_6_button_line:
			try {
				Intent skype_intent = new Intent("android.intent.action.VIEW");
				skype_intent.setClassName("jp.naver.line.android",
						"jp.naver.line.android.activity.SplashActivity");
				startActivity(skype_intent);
			} catch (Exception e) {
				// TODO: handle exception
				Intent browserIntent = new Intent(
						Intent.ACTION_VIEW,
						Uri.parse("https://play.google.com/store/apps/details?id=jp.naver.line.android"));
				startActivity(browserIntent);
			}
			break;
		case R.id.screen_6_button_skype:
			try {
				Intent skype_intent = new Intent("android.intent.action.VIEW");
				skype_intent.setClassName("com.skype.raider",
						"com.skype.raider.Main");
				startActivity(skype_intent);
			} catch (Exception e) {
				// TODO: handle exception
				Intent browserIntent = new Intent(
						Intent.ACTION_VIEW,
						Uri.parse("https://play.google.com/store/apps/details?id=com.skype.raider"));
				startActivity(browserIntent);
			}
			break;

		default:
			break;
		}
	}
}
